﻿

using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using Gift.Model;
using Gift.Model.ENUM;
using Gift.DAL;
using System.Data;

    public partial class admin_index_main :BaseAdmin
    {

        readonly DALAdminLogin theAdminLogin = new DALAdminLogin();
        readonly DALRoleRuleRef theUserRuleRef = new DALRoleRuleRef();
        readonly dalCompany theCompany = new dalCompany();
        readonly DALRule theRule = new DALRule();

        // Methods
        private void Bind()
        {
            this.Label1.Text = count.counts("", "DB_order", "states", "0");
            this.Label2.Text = count.counts("", "DB_order", "states", "1");
            this.Label3.Text = count.counts("", "DB_order", "states", "2");
            this.Label4.Text = count.counts("", "DB_order", "states", "3");
         //   this.Label5.Text = count.counts("", "DB_order", "states", "3");
            this.goods1.Text = count.countsb("", "DB_Shoppro", "visible", "1", "protype", "0");
            this.goods2.Text = count.countsb("", "DB_Shoppro", "visible", "1", "protype", "1");
            this.goods3.Text = count.counts("", "DB_Shoppro", "isnew", "1");
            this.goods4.Text = count.counts("", "DB_Shoppro", "proisprofession", "1");
            this.goods5.Text = count.counts("", "DB_Shoppro", "proiscard", "1");
            this.goods6.Text = count.counts("", "DB_Shoppro", "ispromotion", "1");
            this.msg.Text = count.counts("", "DB_Msg", "1", "1");
            this.comment.Text = count.counts("", "DB_Comment", "1", "1");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
             if (!base.IsPostBack)
            { 
                this.ValidateLoginRule();
                if (Request.QueryString["uid"] == AdminUserId)
                {
                    Response.Write("<script t language=javascript>window.location.href='user/adduser.aspx?uid=" + AdminUserId + "';</script>");
                }
            }
        }


        void ValidateLoginRule()
        {
            int iAdminId = theAdminLogin.GetIdByName(this.Session["Adminlogin"].ToString());
            tbCompany oCompany = theCompany.GetModelByAdminId(iAdminId);

            DataSet ds;
         //   ds = theUserRuleRef.GetListByAdminId(iAdminId, base.AdminShopId);
            ds = theUserRuleRef.GetListByRoleId(iAdminId);
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ERule oERule = (ERule)Enum.Parse(typeof(ERule), dr["Name"].ToString(), true);
                    if (oERule == ERule.OrderProcess)
                    {
                        
                        this.tbOrder.Visible = true;
                        this.Bind();
                        return;
                    }
                  
                }
            }

        }


    }
